package com.dk.controller;

import com.dk.pojo.TabCategory;
import com.dk.pojo.TabSeller;
import com.dk.pojo.User;
import com.dk.service.CategoryService;
import com.dk.service.SellerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("treeController")
public class TreeController {
    @Autowired
    CategoryService categoryService;
    @Autowired
    SellerService sellerService;

    @RequestMapping("toLogin")
    public String toLogin(){
        return "forward:/";
    }
    @RequestMapping("toTree")
    public String toTree(HttpServletRequest request,Model model) {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("userLogin");
        model.addAttribute("user",user);
        return "backstage/treeView";
    }

    @RequestMapping("toRole")
    public String toRole() {
        return "role/show";
    }

    @RequestMapping("toUser")
    public String toUser() {
        return "user/show";
    }

    @RequestMapping("toTravelRoute")
    public String toTravelRoute(Model model) {
        List<TabSeller> sellers = sellerService.getInfo();
        List<TabCategory> categories = categoryService.getInfo();
        model.addAttribute("categories",categories);
        model.addAttribute("sellers",sellers);
        return "travelRoute/show";
    }
    @RequestMapping("toCustomer")
    public String toCustomer() {
        return "Customer/show";
    }

    @RequestMapping("toCategory")
    public String toCategory() {
        return "Category/show";
    }

    @RequestMapping("toSeller")
    public String toSeller() {
        return "Seller/show";
    }

    @RequestMapping("toCarousel")
    public String toCarousel() {
        return "carousel/show";
    }

    @RequestMapping("toAudit")
    public String toAudit(Model model) {
        List<TabSeller> sellers = sellerService.getInfo();
        List<TabCategory> categories = categoryService.getInfo();
        model.addAttribute("categories",categories);
        model.addAttribute("sellers",sellers);
        return "audit/show";
    }





}
